// 
// Entify project
//  
// Author:
//       Lauri Taimila <lauri@taimila.com>
// 
// Copyright (c) 2010 Lauri Taimila
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Collections.Generic;

namespace Taimila.Entify
{
	/// <summary>
	/// Composite filter can be used to group other filters with boolean AND or OR operator.
	/// </summary>
	public sealed class CompositeFilter : IDataFilter
	{
		/// <summary>
		/// Create a new empty AND composite filter.
		/// </summary>
		public CompositeFilter()
		{
			this.Operator = CompositeOperator.And;
			this.Filters = new List<IDataFilter>();
		}
		
		/// <summary>
		/// Create a new AND composite filter with given data filters.
		/// </summary>
		/// <param name="dataFilters">
		/// Data filters to be groupped within AND composite filter. <see cref="IDataFilter[]"/>
		/// </param>
		public CompositeFilter(params IDataFilter[] dataFilters) : this()
		{
			this.Filters.AddRange(dataFilters);
		}
		
		/// <summary>
		/// Create a new composite filter with given data filters and operator.
		/// </summary>
		/// <param name="dataFilters">
		/// Data filters to be groupped within AND composite filter. <see cref="IDataFilter[]"/>
		/// </param>
		public CompositeFilter(CompositeOperator compositeOperator, params IDataFilter[] dataFilters) : this(dataFilters)
		{
			this.Operator = compositeOperator;
		}
		
		/// <summary>
		/// List of data filters grouped by this composite filter.
		/// </summary>
		public List<IDataFilter> Filters
		{
			get;
			set;
		}
		
		/// <summary>
		/// Operator that is used to group inner filters.
		/// </summary>
		public CompositeOperator Operator
		{
			get;
			set;
		}
	}
	
	/// <summary>
	/// Defines operators that can be used with CompositeFilter.
	/// </summary>
	public enum CompositeOperator
	{
		/// <summary>
		/// Logical operator AND.
		/// </summary>
		And,
		
		/// <summary>
		/// Logical operator OR.
		/// </summary>
		Or
	}
}
